/**
 *  *2010-6-17 上午11:09:36  add 
 */
package com.base.myproject.client.HR.setting;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Administrator
 *2010-6-17
 * javazgw@gmail.com
 */
public class HR_relationship_Setting extends BaseJDBCPanel
{
	public HR_relationship_Setting()
	{
		init();
		
	}
	public void init()
	{
		add(initWeigetx());
		registerMainStore(store);
		registerStore(store);
		setdefault();

	}
	private Widget initWeigetx()
	{
		VerticalPanel vpanel = new VerticalPanel();
		vpanel.add(createGrid());
		return vpanel;
		
	}
	
	private void setdefault() {
		store.addDefault("type", "hr_relationship");
		
	}

	BaseStore<BusiObject> store = null;
	BaseStore<BusiObject> getStore(){
	if(store==null) 
	{
		createStore();
	}
	return store;}
	BaseStore<BusiObject> createStore(){
	ModelType type = new ModelType();
	type.setRoot("records");
	type.setRecordName("record");
	type.setTotalName("totle");
	type.addField("icode");
	type.getField("icode").setType(Long.class);
	type.addField("code");
	type.getField("code").setType(String.class);
	type.addField("name");
	type.getField("name").setType(String.class);
	type.addField("type");
	type.getField("type").setType(String.class);
	type.addField("mark");
	type.getField("mark").setType(String.class);
	StoreInfo info = new StoreInfo();
	info.setTablename("dictionary");
	info.setKeyname(new String[] { "icode"});
	info.setSql("select * from dictionary where type='hr_relationship'");
	//info.setParent(mainstore);// 关联主表
	//info.setLinkparentcolumns(new String[] { "icode" }); // 关联主表字段
	//info.setLinkparent_chile_columns(new String[] { "upicode" });// 关联主表字段
	  store = new BaseStore<BusiObject>(type, info);
	  
	 return store;}
	

	BaseGridPanel grid=null;
	BaseGridPanel createGrid(){
	CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
	List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
	columns.add(cbs.getColumn());

//	ColumnConfig C1 = new ColumnConfig("icode", "icode", 80);
//	columns.add(C1);
	ColumnConfig C2 = new ColumnConfig("code", "编码", 80);
	C2.setEditor(new CellEditor(new TextField<String>()));
	columns.add(C2);
	ColumnConfig C3 = new ColumnConfig("name", "名称", 80);
	C3.setEditor(new CellEditor(new TextField<String>()));
	columns.add(C3);
//	ColumnConfig C4 = new ColumnConfig("type", "type", 80);
//	columns.add(C4);
//	ColumnConfig C5 = new ColumnConfig("mark", "mark", 80);
//	columns.add(C5);

	ColumnModel cm = new ColumnModel(columns);
	grid = new BaseGridPanel(getStore(), cm,true,true);
	cbs.setSelectionMode(SelectionMode.SINGLE);
	grid.getBg().setSelectionModel(cbs);
	grid.setHeight(400);
	grid.setWidth(300);
	return grid ;}
}
